﻿package Server.AHMJ.HSMJ;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.apache.commons.lang.ArrayUtils;

import Server.Model.Base.IServerUserItem;

public class Constants {

	public static int HU_TYPE_QIDUI = 1; // 七对子胡
	public static int HU_TYPE_COMMON = 2; // 没有宝牌的胡
 
	static final int INIT_TOTAL = 0;
	static final int INIT_FIRST_ROUND = 1;
	static final int INIT_NEWROUND = 2;

	public static int MAX_CARD_NUM_144 = 144; // 总计144张牌
	public static int MAX_CARD_NUM_136 = 136; // 总计136张牌
	public static int MAX_CARD_NUM_108 = 108; // 总计108张牌
	public static int MAX_CARD_NUM_112 = 112; // 总计112张牌
	
	public static int HAND_MJ_MAX = 14;
	public static int MAX_BLOCK_NUM = 4;

	public static int GAME_END_NORMAL = 0;
	public static int GAME_END_PASS = 1;
	public static int GAME_END_ESCAPE = 2;
	public static int GAME_END_MAXROUND = 3;
	public static int GAME_END_DISMISS = 4;

	public static int GANG_BUPAI = 0xFE; // 杠牌补牌
	public static int RESERVED_PAI = 0xFE; // 杠牌补牌

	public static int FALSE = 0;
	public static int TRUE = 1;

	public static int INVALID_CARD =  0xFF; // 无效的牌
	public static int INVALID_SEAT_VALUE =  0xFF;
	public static int INVALID_CHAIR =  0xFF;

	public static int GS_FREE = 0; // 空闲状态
	public static int GS_PLAYING = 100; // 游戏状态

	// 公共宏定义
	// 结束原因
	public static int GER_NORMAL = 0x00; // 常规结束
	public static int GER_DISMISS = 0x01; // 游戏解散
	public static int GER_USER_LEFT = 0x02; // 用户离开

	//////////////////////////////////////////////////////////////////////////
	// 命令码定义

	public static int SUB_S_GAME_START = 100; // 游戏开始

	public static int SUB_S_ADD_GOLD = 101; // 加注结果
	public static int SUB_S_GIVE_UP = 102; // 放弃跟注
	public static int SUB_S_SEND_CARD = 103; // 发牌消息
	public static int SUB_S_GAME_END = 104; // 游戏结束
	// public static int SUB_S_KAIPAI = 105 ; //开牌 //add
	// public static int SUB_S_KANPAI = 106 ; //看牌 //add
	public static int SUB_S_OVER = 107; // add

	public static int SUB_GF_SCENE = 111;
	public static int SUB_GF_SIT = 112;
	public static int SUB_GF_STANDUP = 113;
	//////////////////////////////////////////////////////////////////////////
	// 消息结构体
	// 用户状态定义
	public static int US_NULL = 0x00; // 没有状态
	public static int US_READY = 0x01; // 同意状态
	public static int US_PLAY = 0x02; // 游戏状态

	public static int US_FREE = 0x10; // 站立状态
	public static int US_SIT = 0x11; // 坐下状态
	public static int US_LOOKON = 0x12; // 旁观状态
	public static int US_OFFLINE = 0x13;

	public static int GAME_KIND = 13;
	// public static int INIT_TOTAL = 0; // 牌局全部清空
	// public static int INIT_FIRST_ROUND = 1; // 牌局全部清空
	// public static int INIT_NEWROUND = 2; // 为了下一把初始化一些东西

	public static int CountArray(int by[]) {
		return by.length;
	}

	public static int sizeof(tagUserReport[] m_kReport) {
		return m_kReport.length;
	}

	public static int countof(int[] by,int by2) {
		int cntCount = 0;
		for (int i = 0; i < by.length; i++) {
			if (by[i] == by2) {
				cntCount++;
			}
		}
		return cntCount;
	}
	public static int countof(int[] by,int by2,int count) {
		int cntCount = 0;
		for (int i = 0; i < count; i++) {
			if (by[i] == by2) {
				cntCount++;
			}
		}
		return cntCount;
	}	
	public static int replace(int[] by,int by1,int by2) {
		int cntCount = 0;
		for (int i = 0; i < by.length; i++) {
			if (by[i] == by1) {
				by[i] = by2;
				cntCount++;
			}
		}
		return cntCount;
	}
	public static int replace(int[] by,int by1,int by2,int count) {
		int cntCount = 0;		
		if(count > 0)
		{
			for (int i = 0; i < by.length; i++) {
				if (by[i] == by1) {
					by[i] = by2;
					cntCount++;
					count--;
					if(count<= 0)
					{
						break;
					}
				}
			}
		}

		return cntCount;
	}	
	public static void CopyMemory(int[] by, int by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = by2;
		}
	}

	public static void CopyMemory(int[] by, int[] by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = by2[i];
		}
	}

	public static void memcpy(int[] by, int[] by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = by2[i];
		}
	}
	public static int memcmp(int[] by, int[] by2, int length) {
		for (int i = 0; i < length; i++) {
			if(by[i] != by2[i])
			{
				return -1;
			}
		}
		return 0;
	}
 
	public static void memset(int[] by, int by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = by2;
		}
	}

	public static Random rd = new Random();
	public static int bai = 40;//设成无效牌

	public static int rand() {
		return rd.nextInt(  1024 );
	}

	public static int rand(int i, int j, int factor) {
		return rd.nextInt(j - i) + i;
	}

	public static int sizeof(IServerUserItem[] m_pIUserItem) {
		return m_pIUserItem.length;
	}

	public static int sizeof(long[] m_LookOnUserID) {
		return m_LookOnUserID.length;
	}

	public static void memset(long[] by, int by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = (long) by2;
		}

	}

	public static int sizeof(SSeatInfo[] m_seatInfo) {
		return m_seatInfo.length;
	}

	public static void memset(SSeatInfo[] m_seatInfo, int by2, int sizeof) {
		for (int i = 0; i < sizeof; i++) {
			m_seatInfo[i] = new SSeatInfo();
		}
	}

	public static void memcpy(HU hu, HU hu2) {
		for(int i=0;i<4;i++)
		{
			hu.block[i].first = hu2.block[i].first;
			hu.block[i].style = hu2.block[i].style;
			hu.block[i].origValue = hu2.block[i].origValue;
		}
		hu.jiangMj = hu2.jiangMj;
	}

	public static final int BLOCK_NULL = 0; // 无
	public static final int BLOCK_CHI = 1; // 吃牌结构
	public static final int BLOCK_SUN = 2; // 顺序结构
	public static final int BLOCK_PENG = 3; // 碰子结构,3个相同
	public static final int BLOCK_KE = 4; // 刻子结构,3个相同,非碰
	public static final int BLOCK_GANG = 5; // 杠子结构,4个相同
	public static final int BLOCK_AN_GANG = 6; // 暗杠
	public static final int BLOCK_BU_GANG = 7; // ²¹¸Ü		
	public static final int BLOCK_CHI_BAI = 8; 
	public static final int ZHUANG_JIA = 0;

	public static final int PI_HU = 0;
	

	public static final int TUI_DAO_HU = 0;
	public static final int PING_HU = 4;//Æ½ºú 1·¬2±¶ ´øÁ¬´ø
	public static final int QUAN_QIU_REN = 5; //È«ÇóÈË 1·¬ 2·Ö
	public static final int PENG_PENG_HU = 6;//ÅöÅöºú 2·¬ 4·Ö
	public static final int GANG_KAI = 7;//¸ÕÉÏ¿ª»¨ 1·¬ 2·Ö
	public static final int QI_DUI_ZI = 8;//Æß¶Ô×Ó 2·¬ 4·Ö
	public static final int QING_QI_DUI_ZI = 9;//ÇåÆß¶Ô×Ó 4·¬ 16·Ö
	public static final int QI_DUI_ZI_BAO_TOU = 10;//Æß¶Ô×Ó±¬Í· 8·¬64±¶
	
	public static final int QING_YI_SE = 15;//ÇåÒ»É« ÓÐ²ÆÉñ 2·¬ 4·Ö
	public static final int CHUN_QING_YI_SE = 16;//ÇåÒ»É« ÎÞ²ÆÉñ 4·¬ 16·Ö
	public static final int HUN_YI_SE = 17;//»ìÒ»É« 2·¬ 4·Ö
	public static final int BAO_TOU = 18; //±¬Í·£¨ÇÃÏì£© 2·¬ 4·Ö
	public static final int CAI_SHEN_TOU = 19;//²ÆÉñÍ· 4·¬ 16·Ö
	public static final int GANG_DI_HUA = 20;//杠底花
	public static final int HAI_DI_LAO_YUE = 26;//º£µ×ÀÌÔÂ 2±¶·¬Êý

	public static final int TIAN_HU = 30;//Ììºú 2·¬ 4·Ö
	public static final int DI_HU = 31;//µØºú 2·¬ 4·Ö
	public static final int REN_HU = 32;//ÈËºú 2·¬ 4·Ö
	public static final int GANG_BAO = 33;//¸Ü±¬ 4·¬ 16·Ö
	public static final int QING_FENG = 35;//Çå·ç 4·¬ 16·Ö
	public static final int LUAN_FENG = 36;//ÂÒ·ç 4·¬16·Ö
	public static final int SHI_SAN_BU_KAO = 37;//Ê®Èý²»¿¿ 1·¬2·Ö
	public static final int QI_FENG_BU_KAO = 38;//Ê®Èý²»¿¿ Æß·ç 2·¬4·Ö
	public static final int SAN_CAI_YI_KE = 40;//Èý²ÆÒ»¿Ì 4·¬16·Ö
	
	public static Object sizeof(HU hu) {
		return null;
	}

	public static void memcpy(HU hu, HU hu2, Object sizeof) {
		memcpy(hu, hu2);
	}

	public static int sizeof(int[] byParam) {
		return byParam.length;
	}


	static final int ACTION_WITH_ROBOT = 100;

	static final int ACTION_GIVE_UP = 0;
	static final int ACTION_FA_PAI = 1;
	static final int ACTION_MO_PAI = 2;
	static final int ACTION_CHU_PAI = 3;
	static final int ACTION_CHI = 4;
	static final int ACTION_PENG = 5;
	static final int ACTION_GANG = 6;
	static final int ACTION_TING = 7; // ³öÅÆ£¬²»ÓÃÓÚÈ¨ÏÞ£¬½öÓÃÓÚÁ¢Ö±Ò»·¢
	static final int ACTION_HU = 8;
	static final int ACTION_HUANPAI = 10;
	static final int ACTION_GANG_BUPAI = 11;
	static final int ACTION_BU_HUA = 12;
	
	static final int ACTION_QIAOXIANG = 13;

	
	
	public static void Sort(int byHandCard[]) {
		for (int i = 0; i < byHandCard.length - 1; i++) {
			for (int j = i; j < byHandCard.length; j++) {
				int x = byHandCard[i];
				int y = byHandCard[j];
				if (x > y) {
					int tempvalue = byHandCard[i];
					byHandCard[i] = byHandCard[j];
					byHandCard[j] = tempvalue;
				}
			}
		}
	}

	public static final int[] FENGS= new int[]{27,	28,	29,	30};
}
